
import com.sun.org.apache.bcel.internal.generic.FSUB;
import com.sun.org.apache.xml.internal.utils.SuballocatedByteVector;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class TreeSerialization {
    private static StringBuffer sb =new StringBuffer();
    // 二叉树节点定义
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x) { val = x; }
    }
    // Encodes a tree to a single string.
    public static String serialize(TreeNode root) {
        sb.append("[").append(root.val);
        subPrint(root.left);
        subPrint(root.right);
        return sb.toString();
    }
    private static String subPrint(TreeNode node){
        if (node == null )
            return sb.toString();
        sb.append(",").append(node.val);
        sb.append(",").append(node.left.val);
        sb.append(",").append(node.right.val);
        return sb.toString();
    }

 /*   // Decodes your encoded data to tree.
    public TreeNode deserialize(String data) {

    }

    public TreeNode help(String[] strArr, int[] index) {

    }*/
    // 测试用例
    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.right = new TreeNode(3);
        root.right.left = new TreeNode(4);
        root.right.right = new TreeNode(5);
        String serialized = serialize(root);
        System.out.println(serialized);
    }
}
